<?php
namespace Manage\Controller;

class ApiController extends CommonController {
    public function VerifyCode(){
        $Verify = new \Think\Verify();
        $Verify->entry();
    }

    public function CheckVerifyCode($code){
        $Verify = new \Think\Verify();
        return $Verify->check($code);
    }

    public function DropServer(){
        $sid = (int)I('get.d');
        if( $sid > 0 ){
            $db = zyt_data_init();
            $map['game_server_id'] = $sid;
            $result = $db->table('game_server')->where($map)->delete();
            $this->ajaxReturn($result ? true : false);
        }

    }

    public function UserInfo(){
        $uid = (int)I('post.uid');
        if( $uid > 0 ){
            $db = zyt_data_init();
            $result = $db->table('User as A')->field('A.user_id, A.user_name, A.user_phone, A.user_email, B.tong_money_count, B.consumed_money_count')->join('user_capital as B', 'A.user_id', 'B.capital_user_id')->where("A.user_id = '$uid'")->find();

            $this->assign('uid', $result['user_id']);
            $this->assign('username', $result['user_name']);
            $this->assign('mobile', $result['user_phone']);
            $this->assign('email', $result['user_email']);
            $this->assign('tb', price($result['tong_money_count']));
            $this->assign('xf', price($result['consumed_money_count']));
            $this->display('Public/UserInfoTips');
        }
    }

    public function chkUsernameIsExists(){
        //检测用户名
        $db = zyt_data_init();
        $name=trim(I('post.user_name'));
        $uid=(int)I('post.user_id');
        if(empty($name)) $this->ajaxReturn(false);
        $where = "(user_name = '$name' OR user_email = '$name' OR user_phone = '$name')";
        if( $uid > 0 ){
            $where .= " AND user_id <> $uid";
        }
        $ckuser = $db->table('user')->where($where)->find();

        if( !empty($ckuser) ){
            $result = false;
        }else{
            $result = true;
        }
        $this->ajaxReturn($result);
    }
}